Skip to content

feat: implemented fallback mechanism for when CNI does not provide an…#4439

Open
estebancams wants to merge 3 commits into
masterfrom
estebanca/cni-hns-provider-address
Open

feat: implemented fallback mechanism for when CNI does not provide an…#4439
estebancams wants to merge 3 commits into
masterfrom
estebanca/cni-hns-provider-address

Conversation

@estebancams
Copy link
Copy Markdown
Contributor

@estebancams estebancams commented Jun 2, 2026

WIP

HNS team has made changes that allow to create a dual-stack network when an ipv4-only network has already been associated with an interface. Previously this was not possible (although it was possible to create such networks in the reverse order).

This change has a side effect in HNS behavior for when the Adapter Name is not passed as part of the creation payload in a node with multiple adapters:

Before the change:

  • User creates a ipv4 network
  • User creates a dual-stack network but is does not indicate the name of the adapter to which it should be associated
  • HNS selects an adapter different from the one associated to the ipv4 network to create the dual-stack network

After the change:

  • User creates a ipv4 network
  • User creates a dual-stack network but is does not indicate the name of the adapter to which it should be associated
  • HNS could select the same adapter as the one associated to the ipv4 network to create the dual-stack network. Current users are not expecting the dual-stack network to be created in the same adapter, so HNS will require explicitely passing the adapter name if the user intention is to associate the dual-stack network with the same ipv4's adapter.

Coincidentally, CNI is passing an empty adapter name when there is any network already created in the node. This is because HNS fails to associate a new network with a virtual (vEthernet) adapter. This happens because the original Ethernet adapter becomes the uplink of the vSwitch where the network is created on and a new network has to be associated with that adapter.

HNS team proposed extending HNS creation API so CNI can pass instead of the adapter name, the IP of the original adapter.

The change in this PR uses that new API when adapter name is going to be passed empty to HNS during network creation. Note the change does not migrate from adapter name to IP APIs, but it only covers the existent gap. Also, this change will continue to be a best effort action and if the IP address cannot be passed to HNS for whatever reason, the call to HNS will still be made regardless (CNI should not fail in scenarios where it previously didn't)

Copilot AI review requested due to automatic review settings June 2, 2026 19:27
@estebancams estebancams requested review from a team as code owners June 2, 2026 19:27
@estebancams estebancams requested a review from tamilmani1989 June 2, 2026 19:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a Windows fallback mechanism for HCN network adapter selection when an adapter name policy can’t be applied (e.g., vSwitch/vEthernet scenarios), using the NC PrimaryInterfaceIdentifier to build a provider-address policy.

Changes:

  • Rename the existing adapter-name policy helper and update call sites.
  • Introduce a new HCN network policy helper for ProviderAddress and apply it as a fallback in Windows HCN network configuration.
  • Plumb PrimaryInterfaceIdentifier from the CNS NC response into network.EndpointInfo and add Windows unit tests for the fallback behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
network/policy/policy_windows.go Renames the adapter name policy helper and adds a provider-address policy helper.
network/network_windows.go Applies adapter-name policy when possible; otherwise attempts provider-address fallback based on PrimaryInterfaceIdentifier.
network/network_windows_test.go Adds tests validating provider-address fallback vs adapter-name behavior.
network/endpoint.go Extends EndpointInfo with PrimaryInterfaceIdentifier.
cns/hnsclient/hnsclient_windows.go Updates call site to renamed adapter-name policy helper.
cni/network/network.go Copies PrimaryInterfaceIdentifier from NC response into EndpointInfo.

Comment thread network/policy/policy_windows.go
Comment thread network/network_windows.go Outdated
Comment on lines 265 to 287
if !netAdapterNamePolicyAdded {
primaryInterfaceIdentifier := nwInfo.PrimaryInterfaceIdentifier
if primaryInterfaceIdentifier == "" {
return nil, errors.New("PrimaryInterfaceIdentifier is empty. Adapter Address policy can't be applied")
}

var providerAddress string
// Based on cns/NetworkContainerContract.go, PrimaryInterfaceIdentifier can be either an IP or a CIDR
if ip, _, err := net.ParseCIDR(primaryInterfaceIdentifier); err == nil {
providerAddress = ip.String()
} else if ip := net.ParseIP(primaryInterfaceIdentifier); ip != nil {
providerAddress = ip.String()
} else {
return nil, fmt.Errorf("PrimaryInterfaceIdentifier %q is not a valid IP or CIDR", primaryInterfaceIdentifier)
}

adapterAddressPolicy, err := policy.GetHcnNetAdapterAddressPolicy(providerAddress)
if err != nil {
return nil, fmt.Errorf("Failed to serialize network adapter address policy: %w", err)
}

hcnNetwork.Policies = append(hcnNetwork.Policies, adapterAddressPolicy)
}
@estebancams
Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@estebancams estebancams force-pushed the estebanca/cni-hns-provider-address branch from a08546f to 8a491e8 Compare June 5, 2026 21:48
@estebancams
Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

@estebancams
Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants